﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FDA_Code
{
    public partial class FormMain : Form
    {
        public FormMain()
        {
            InitializeComponent();
        }

        InitFile init = new InitFile();
        MsSqlHelper mssql = new MsSqlHelper();
        AppCode app = new AppCode();

        private void FormMain_Load(object sender, EventArgs e)
        {
            init.ClearLog();
        }

        private void 查询ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string srq = SdTP.Value.ToString("yyyy-MM-dd");
            string erq = EdTP.Value.ToString("yyyy-MM-dd");
            string sql = "select a.erp_id,rtrim(d.name) as code,convert(varchar(20),a.created_at,20) as created_at,a.partner_code,rtrim(a.partner_name) as partner_name,b.fda_code \r\n"
                + " from wms_move a(nolock) \r\n"
                + " inner join wms_move_detail b(nolock) on a.id=b.master_id \r\n"
                + " inner join wms_inv c(nolock) on b.inv_id=c.id \r\n"
                + " left join sys_user d(nolock) on a.created_by=d.id \r\n"
                + " where b.fda_code is not null \r\n"
                + " and c.manu like '%哈药%' \r\n"
                + " and convert(varchar(20),a.created_at,20) between '" + srq + "' and '" + erq + "' \r\n"
                + " order by a.created_at desc";
            DataTable dt = mssql.ExecuteDt(sql);
            dGV.DataSource = dt;
            init.DataViewColumn(dGV,"");
            init.AutoSizeColumn(dGV);
            //app.SaveXML(dt);
            app.DtHz(dt);
        }

        private void dGV_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            var grid = sender as DataGridView;
            var rowIdx = (e.RowIndex + 1).ToString();

            var centerFormat = new StringFormat()
            {
                // right alignment might actually make more sense for numbers  
                Alignment = StringAlignment.Center,
                LineAlignment = StringAlignment.Center
            };

            var headerBounds = new Rectangle(e.RowBounds.Left, e.RowBounds.Top, grid.RowHeadersWidth, e.RowBounds.Height);
            e.Graphics.DrawString(rowIdx, this.Font, SystemBrushes.ControlText, headerBounds, centerFormat);  
        }
    }
}
